package com.ai_chat.sys.service.impl;

import com.ai_chat.sys.entity.Topic;
import com.ai_chat.sys.mapper.TopicMapper;
import com.ai_chat.sys.service.ITopicService;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;


@Service
public class TopicServiceImpl extends ServiceImpl<TopicMapper, Topic> implements ITopicService {
    @Autowired
    private TopicMapper topicMapper;

    public List<Topic> getTopicList(Integer userId){
        LambdaQueryWrapper<Topic> condition = new LambdaQueryWrapper<>();
        condition.eq(Topic::getUserId, userId);

        condition.orderByDesc(Topic::getId);
        return topicMapper.selectList(condition);
    }

    public void createTopic(Topic topic){
        topicMapper.insert(topic);
    }

    public void deleteTopic(Topic topic){

        topicMapper.deleteById(topic);
    }

    public void deleteUserTopicList(Topic topic){
        LambdaQueryWrapper<Topic> condition = new LambdaQueryWrapper<>();
        condition.eq(Topic::getUserId, topic.getUserId());
        topicMapper.delete(condition);
    }

}
